#include"Dcitionary.hpp"
#include"DictServer.hpp"

void Usage(std::string proc)
{
    std::cerr << "Usage: " << proc << " serverport" << std::endl;
}

//./server serverport
int main(int argc , char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        return 0;
    }
    //指定刷新策略
    EnableConsoleLogStrategy();

    uint16_t port = std::stoi(argv[1]);

    const std::string path = "./dict.txt";
    Dictionary dict(path);

    std::unique_ptr<DictServer> usvr = std::make_unique<DictServer>(port , 
        [&dict](const std::string word , const std::string wordip , uint16_t wordport)->std::string
        { return dict.Translate(word , wordip , wordport);});

    usvr->Init();
    usvr->Start();
    return 0;
}